package com.lupan.tomcatStudy.javaStudy.chapter17;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * TODO socket编程服务器端
 *
 * @author lupan
 * @version 2016/1/19 0019
 */
public class Server {

    public static void main(String[] args) throws Exception{

        //创建用于监听的socket
        ServerSocket ss = new ServerSocket(30000);

        while(true){
            Socket s = ss.accept();

            //向客户端发送信息
            PrintStream ps = new PrintStream(s.getOutputStream());
            ps.println("服务器端收到信息！");
//            ps.close();

            //读取客户端信息
            Reader reader = new InputStreamReader(s.getInputStream());
            BufferedReader bufferedReader = new BufferedReader(reader);
            while(true){
                System.out.println("接收到客户端"+s.getLocalAddress().getHostAddress()+"信息:"+bufferedReader.readLine());
            }



//            s.close();

        }
    }
}
